/**
 * 
 */
package com.mie.producer;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author Mie
 *
 */
public class Producer_HelloWorld {
	public static void main(String[] args) throws IOException, TimeoutException {
		//1.create factory
		ConnectionFactory factory=new ConnectionFactory();
		//2.set parameter
		factory.setHost("localhost");//defaults localhost
		factory.setPort(5672);
		factory.setVirtualHost("/");
		factory.setUsername("rollen");
		factory.setPassword("root");
		//3.create connection
		Connection connection=factory.newConnection();
		//4.create channel 
		Channel channel=connection.createChannel();
		//5.declare queue
		channel.queueDeclare("hello_world",true,false,false,null);
		String queue="hello rabbitmq!";
		//6.send message
		/*
		 exchange the exchange to publish the message to
		 routingKey the routing key
		 props other properties for the message - routing headers etc
		 body the message body
		 */
		channel.basicPublish("", "hello_world", null, queue.getBytes());
		//7.release sources
		channel.close();
		connection.close();
		
	}

}
